import request from './request'

export interface ApiResponse<T = any> {
  code: number
  message: string
  data: T
}

export interface ProjectTask {
  id: number
  projectId: number
  description: string
  assignedTo: number
  assignedToName: string
  beginDate: string
  dueDate: string
  status: number
  actualEndDate?: string
  createdAt: string
  updatedAt: string
}

export interface CreateTaskRequest {
  projectId: number
  description: string
  assignedTo: number
  beginDate: string
  dueDate: string
}

export interface UpdateTaskRequest {
  id: number
  description: string
  assignedTo: number
  beginDate: string
  dueDate: string
  status: number
}

export interface TaskListParams {
  projectId: number
  keyWord?: string
  status?: number
  beginTime?: string
  endTime?: string
  dueBeginTime?: string
  dueEndTime?: string
  isMy?: boolean
  pageDto: {
    pageNumber: number
    pageSize: number
  }
}

export interface PagedResult<T> {
  items: T[]
  totalCount: number
  pageNumber: number
  pageSize: number
}

// 获取任务列表
export const getTaskList = (params: TaskListParams): Promise<ApiResponse<PagedResult<ProjectTask>>> => {
  return request.post('/projecttask/getList', params)
}

// 创建任务
export const createTask = (data: CreateTaskRequest): Promise<any> => {
  return request.post('/projecttask/addTask', data)
}

// 更新任务
export const updateTask = (data: UpdateTaskRequest): Promise<any> => {
  return request.post('/projecttask/updateTask', data)
}

// 删除任务
export const deleteTask = (id: number): Promise<any> => {
  return request.post('/projecttask/delById', { id })
}


